package com.pinda.controller;


import com.github.pagehelper.PageInfo;
import com.pinda.base.entity.PdFleet;
import com.pinda.base.search.PdFleetSearch;
import com.pinda.base.vo.FleetVo;
import com.pinda.commonutils.Page;
import com.pinda.commonutils.Result;
import com.pinda.commonutils.StatusCode;

import com.pinda.feign.FleetFeign;
import com.pinda.service.IPdFleetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车队表 前端控制器
 * </p>
 *
 * @author lc
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd_fleet")
public class PdFleetController {



    @Autowired
    IPdFleetService pdFleetService;

    @Autowired
    FleetFeign fleetFeign;


    @RequestMapping("/queryAllFleet")
    public Result<PdFleet> queryAllFleet(){
        List<PdFleet> list = this.pdFleetService.list();
        if(!list.isEmpty()){
            return new Result(true, StatusCode.OK,"查询成功",list);
        }
        return new Result(false,StatusCode.ERROR,"查询失败",list);
    }

    @RequestMapping("/queryFleetAndTruckAndUser")
    public List queryFleetAndTruckAndUser(){
        return this.fleetFeign.queryFleetAndTruckAndUser();
    }


    @PostMapping("findFleetByName")
    public PageInfo<FleetVo> findFleetByName(@RequestBody Page<PdFleetSearch> page){
        System.out.println(page);
        return pdFleetService.findFleetByName(page);
    }


    @GetMapping("delFleetById")
    public boolean delFleetById(String id){
        return pdFleetService.removeById(id);
    }

    /**
     * 添加FleetById
     * @param pdFleet
     * @return
     */
    @PostMapping("addFleetById")
    public boolean addFleetById(@RequestBody PdFleet pdFleet){
        return pdFleetService.save(pdFleet);
    }

    @PostMapping("updFleet1")
    public boolean updFleet1(@RequestBody PdFleet pdFleet){
        return  pdFleetService.updateById(pdFleet);
    }

    @GetMapping("/selectFleet/{fleetId}")
    public PdFleet selectFleet(@PathVariable("fleetId") String fleetId){
        return pdFleetService.selectFleet(fleetId);
    }

}
